<template>
    <div id="AsnDetailList">
        <v-tableTitle :btnConfig="btnConfig" :tableSelectData="selectData" @backList="backList"
                      @del="del" @newCreate="newCreate"></v-tableTitle>
        <div class="detail">
            <component :data="{detailData,argument}" :is="currentComponent"></component>
        </div>
    </div>

</template>

<script>
    import tableTitle from "commons/TableTitle";
    import navMenu from "commons/NavMenu";
    import baseMixin from "@/mixins/BaseMixin";
    import config from "../Config"

    export default {
        name: "DetailList",
        mixins: [baseMixin, config],
        data() {
            return {
                newFlag: false,
                detailsFlag: false,
                argument: {},
                detailData: {},
                selectData: [],
                detailNav: "1",
                componentConfig: [
                    {
                        name: "Table",
                        label: "table",
                        component: () => import('./page/Table.vue')
                    },
                    {
                        name: "GatherDetailDetail",
                        label: this.$t('common.detail'),
                        component: () => import('./page/particularsDetail.vue')
                    },
                ]
            }
        },
        computed: {
            btnConfig() {
                if (this.detailNav == 1) {
                    return [
                        {label: this.$t('common.create'), certigier: this.newStatus, invalid: "newCreate"},
                        {label: this.$t('common.delete'), certigier: this.deleteStatus, disabled: true, invalid: "del"},
                    ]
                } else if (this.$store.state.newFlag) {
                    return []
                } else {
                    return [
                        {label: this.$t('common.return'), invalid: "backList"},
                    ]
                }
            },
            currentComponent() {
                return this.componentConfig[this.detailNav - 1].component;
            }
        },
        methods: {
            //删除数据
            async del(data) {
                try {
                    let res = await this.$api.post(`/deleteContractDetail/${this.$store.state.wms}`, data);
                    
                        this.$message.success(res.returnMgr);
                        this.$children[1].getTableData(1, {})
                    
                } catch (e) {
                    this.$message.error(e);
                } finally {
                    this.$children[1].$refs.table.delSelectData(data);
                }
            },
            //选中的数据
            setSelectData(data) {
                this.selectData = data;
            },
            //返回试图
            backList() {
                this.detailNav = "1";
                this.detailsFlag = false;
            },
            //新建
            async newCreate() {
                this.detailData = {};
                this.detailsFlag = true;
                this.detailNav = "2";
            },
            async setdialog(data) {
                try {
                    let res = await this.$api.get(`/queryContractDetailByCode/${this.$store.state.wms}/${this.argument.contract_key}/${data.contract_det_key}`);
                    
                        this.detailData = res.bean;
                        this.detailsFlag = true;
                        this.detailNav = "2";
                    
                } catch (e) {
                    this.$message.error(e);
                }
            }
        },
        mounted() {
            
            this.newFlag = this.$store.state.newFlag;
            if (this.newFlag) {
                this.detailData = {};
                this.detailNav = "2";
            } else if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                this.argument = data.routeData;
                this.detailData = data.detailList;
                this.detailNav = data.detailListNav;
                this.detailsFlag = data.detailListFlag;
            } else {
                this.argument = this.$store.state.routeData;
            }

        },
        components: {
            "v-tableTitle": tableTitle,
            "v-navMenu": navMenu,
        },
        watch: {
            selectData(data) {
                if (this.permissionStatus) {
                    if (data.length > 0) {
                        this.deleteStatus = false;
                    } else {
                        this.deleteStatus = true;
                    }
                }
            }
        }
    }
</script>

<style>

</style>
